package general.dbClass;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DBExif {
	private String 	imgHeight;
	private String 	imgWidth;
	private String 	exposureTime;
	private String 	fnumber;
	private String 	exposureProgram;
	private String 	timeDigitized;
	private String 	timeOriginal;
	private String 	colorSpace;
	private String 	exifImgWidth;
	private String 	exifImgHeight;
	private String 	exposureMode;
	private String 	make;
	private String 	model;
	private String 	orietation;
	private String 	xResolution;
	private String 	yResolution;
	
	private int 	imgHeightValue 		= 0;
	private int		imgWidthValue		= 0;
	private float 	exposureTimeValue	= 0.0f;
	private float 	fnumberValue		= 0.0f;
	private Date	timeDigitizedValue	= null;
	private Date	timeOriginalValue	= null;
	private int		exifImgWidthValue	= 0;
	private int 	exifImgHeightValue	= 0;
	private int 	xResolutionValue	= 0;
	private int 	yResolutionValue	= 0;
	
	
	public DBExif(	
			String imgHeight,
			String imgWidth,
			String exposureTime,
			String fnumber,
			String exposureProgram,
			String timeDigitized,
			String timeOriginal,
			String colorSpace,
			String exifImgWidth,
			String exifImgHeight,
			String exposureMode,
			String make,
			String model,
			String orietation,
			String xResolution,
			String yResolution
			)
	{
		this.colorSpace 	= colorSpace;
		this.exifImgHeight 	= exifImgHeight;
		this.exifImgWidth	= exifImgWidth;
		this.exposureProgram= exposureProgram;
		this.exposureMode	= exposureMode;
		this.exposureTime	= exposureTime;
		this.fnumber		= fnumber;
		this.imgHeight		= imgHeight;
		this.imgWidth		= imgWidth;
		this.make			= make;
		this.model			= model;
		this.orietation		= orietation;
		this.timeDigitized 	= timeDigitized;
		this.timeOriginal	= timeOriginal;
		this.xResolution	= xResolution;
		this.yResolution	= yResolution;
		
		this.setValue();
	}
	
	private void setValue() {
		if(imgHeight != null && !imgHeight.equals("")) {
			try{
				this.imgHeightValue = Integer.parseInt(imgHeight.replace(" pixels", ""));
			}catch(Exception e) {
			}
		}
		
		if(imgWidth !=null && !imgWidth.equals("")) {
			try{
				this.imgWidthValue = Integer.parseInt(imgWidth.replace(" pixels", ""));
			}catch(Exception e) {
			}
		}
		
		if(exposureTime != null && !exposureTime.equals("")) {
			try {
				exposureTime = exposureTime.replace(" sec", "");
				if (exposureTime.indexOf('/') >= 0) {
					exposureTimeValue = (float) (1.0 * Integer.parseInt(exposureTime.split("/")[0]) / Integer.parseInt(exposureTime.split("/")[1]));
				} else {
					exposureTimeValue = (float) (1.0 * Float.parseFloat(exposureTime));
				}
	
			} catch (Exception e) {
			}
		}
		
		if(fnumber != null && !fnumber.equals("")) {
			try {
				fnumberValue = Float.parseFloat(fnumber.replace("F", "").replace(",", "."));
			} catch (Exception e) {
			}
		}
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
		if(timeOriginal != null && !timeOriginal.equals("")) {
			try {
				timeOriginalValue = sdf.parse(timeOriginal);
			} catch (Exception e) {
			}
		}
		
		if(timeDigitized !=null && !timeDigitized.equals("")) {
			try {
				timeDigitizedValue = sdf.parse(timeDigitized);
			} catch (Exception e) {
			}
		}
		
		if(exifImgWidth != null && !exifImgWidth.equals("")) {
			try {
				exifImgWidthValue = Integer.parseInt(exifImgWidth.replace(" pixels", ""));
			} catch (Exception e) {
			}
		}
		
		if(exifImgHeight != null && !exifImgHeight.equals("")) {
			try {
				exifImgHeightValue = Integer.parseInt(exifImgHeight.replace(" pixels", ""));
			} catch (Exception e) {
			}
		}
		
		if(xResolution !=null && !xResolution.equals("")) {
			try {
				xResolutionValue = Integer.parseInt(xResolution.replace(" dots per inch", ""));
			} catch (Exception e) {
			}
		}
		
		if(yResolution !=null && !yResolution.equals("")) {
			try {
				yResolutionValue = Integer.parseInt(yResolution.replace(" dots per inch", ""));
			} catch (Exception e) {
			}
		}
	}

	public String getColorSpace() {
		return this.colorSpace;
	}
	
	public String getExifImgHeight() {
		return this.exifImgHeight;
	}
	
	public String getExifImgWidth() {
		return this.exifImgWidth;
	}
	
	public String getExposureProgram() {
		return this.exposureProgram;
	}
	
	public String getExposureTime() {
		return this.exposureTime;
	}
	
	public String getExposureMode() {
		return this.exposureMode;
	}
	
	public String getFnumber() {
		return this.fnumber;
	}
	
	public String getImgHeight() {
		return this.imgHeight;
	}
	
	public String getImgWidth() {
		return this.imgWidth;
	}
	
	public String getMake() {
		return this.make;
	}
	
	public String getModel() {
		return this.model;
	}
	
	public String getOrietation() {
		return this.orietation;
	}
	
	public String getTimeDigitized() {
		return this.timeDigitized;
	}
	
	public String getTimeOriginal() {
		return this.timeOriginal;
	}
	
	public String getXResolution() {
		return this.xResolution;
	}
	
	public String getYResolution() {
		return this.yResolution;
	}


	/**
	 * @return the imgHeightValue
	 */
	public int getImgHeightValue() {
		return imgHeightValue;
	}


	/**
	 * @return the imgWidthValue
	 */
	public int getImgWidthValue() {
		return imgWidthValue;
	}

	/**
	 * @return the exposureTimeValue
	 */
	public float getExposureTimeValue() {
		return exposureTimeValue;
	}

	/**
	 * @return the timeDigitizedValue
	 */
	public Date getTimeDigitizedValue() {
		return timeDigitizedValue;
	}

	/**
	 * @return the timeOriginalValue
	 */
	public Date getTimeOriginalValue() {
		return timeOriginalValue;
	}

	/**
	 * @return the exifImgWidthValue
	 */
	public int getExifImgWidthValue() {
		return exifImgWidthValue;
	}

	/**
	 * @return the exifImgHeightValue
	 */
	public int getExifImgHeightValue() {
		return exifImgHeightValue;
	}

	/**
	 * @return the xResolutionValue
	 */
	public int getxResolutionValue() {
		return xResolutionValue;
	}

	/**
	 * @return the yResolutionValue
	 */
	public int getyResolutionValue() {
		return yResolutionValue;
	}

	/**
	 * @return the fnumberValue
	 */
	public float getFnumberValue() {
		return fnumberValue;
	}
}
